import 'package:base_flutter/base_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter/src/widgets/framework.dart';
import 'package:ls_work/res/colors.dart';

import '../../viewmodel/device/device_repair_building_view_model.dart';
import 'device_repair_list_fragment.dart';

class DeviceRepairPage extends BaseStatefulMvvmWidget {
  @override
  State<StatefulWidget> createState() => _DeviceRepairState();
}

class _DeviceRepairState
    extends BaseMvvmState<DeviceRepairBuildingViewModel, DeviceRepairPage> {
  @override
  Widget buildLoadingContentView() {
    return DefaultTabController(
        length: viewModel.buildingList.length,
        child: Column(
          children: [
            Row(
              children: [
                TabBar(
                        // unselectedLabelColor: Colors.black,
                        // labelColor: Colours.app_main,
                        indicatorColor: Colours.app_main,
                        isScrollable: true,
                        unselectedLabelStyle:
                            TextStyle(fontSize: 15, color: Color(0xff545454)),
                        labelStyle: TextStyle(
                            fontSize: 18,
                            color: Colors.black,
                            fontWeight: FontWeight.bold),
                        indicatorSize: TabBarIndicatorSize.label,
                        tabs: viewModel.buildingList
                            .map((e) => Tab(
                                  text: e.iBuildingName,
                                ))
                            .toList())
                    .setWeight(1),
                IconButton(
                    onPressed: () {},
                    icon: Icon(Icons.keyboard_arrow_down_rounded))
              ],
            ).addToContainer(color: Colors.white),
            TabBarView(
                    children: viewModel.buildingList
                        .map((e) => DeviceRepairListFragment(e.iBuildingId))
                        .toList())
                .setWeight(1),
            ElevatedButton(
                    onPressed: () {
                      viewModel.scanCode();
                    },
                    style: ButtonStyle(
                        backgroundColor:
                            WidgetStateProperty.all(Colours.app_main),
                        minimumSize: WidgetStateProperty.all(
                            Size(double.infinity, 50))),
                    child:
                        CommonText('扫码', textColor: Colors.white, textSize: 17))
                .addToContainer(
                    margin: EdgeInsets.symmetric(horizontal: 16, vertical: 10))
          ],
        ));
  }

  @override
  Widget buildRootView(BuildContext context, Widget loadingContentWidget) {
    return Scaffold(
      backgroundColor: Color(0xfff1f1f1),
      appBar: AppBar(
        title: Text('设备维保管理'),
      ),
      body: loadingContentWidget,
    );
  }

  @override
  DeviceRepairBuildingViewModel createViewModel() {
    return DeviceRepairBuildingViewModel(context);
  }

  @override
  void onRetryClick() {
    viewModel.getBuildingList();
  }
}
